<include file="public@header_vue"/>
</head>
<style>
    .el-pagination {
        margin-top: 20px;
    }


    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }

    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }

    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .photos {
        width: 120px;
        height: 120px;
        border-radius: 6px;
        overflow: hidden;
        float: left;
        margin-right: 10px;
        margin-bottom: 10px;
        position: relative;
    }

    .photos-options {
        position: absolute;
        top: 0;
        left: 0;
        height: 120px;
        line-height: 120px;
        width: 120px;
        text-align: center;
        background-color: rgba(0, 0, 0, 0.6);
        z-index: 10;
        opacity: 0;
        transition: opacity 0.6s;
    }

    .photos:hover .photos-options {
        opacity: 1;
    }

    .photos-options .el-button {
        font-size: 24px;
        color: white
    }

    .photos img {
        width: 120px;
        height: 120px;
    }

    .photos-uploader {
        width: 120px;
        height: 120px;
        float: left;
    }

    .logo-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .logo-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .logo-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 120px;
        height: 120px;
        line-height: 120px;
        text-align: center;
    }
</style>
<body>
<div id="app">
    <el-tabs type="border-card">
        <el-tab-pane label="活动报名列表" v-loading="onDataLoading">
            <el-row>
                <el-col :span="24">
                    <el-form :inline="true" :model="form" size="mini">
                        <el-form-item label="日期:">
                            <el-date-picker v-model="form.duration" type="daterange" value-format="yyyy-MM-dd"
                                            :picker-options="durationOptions" range-separator="至"
                                            start-placeholder="开始日期" end-placeholder="结束日期" clearable></el-date-picker>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="getData()">查询</el-button>
                            <el-button type="danger" @click="clearForm()">清空</el-button>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
            <el-table :data="tableData" style="width: 100%">
                <el-table-column prop="id" label="ID" width="80"></el-table-column>
                <el-table-column prop="avatar" label="用户头像">
                    <template slot-scope="scope">
                        <img :src="scope.row.user_info.headimgurl" style="width: 100px;" alt="">
                    </template>
                </el-table-column>
                <el-table-column prop="user_info.nickname" label="用户昵称"></el-table-column>
                <el-table-column prop="activity_info.title" label="活动标题"></el-table-column>
                <el-table-column prop="cover_img" label="封面图片">
                    <template slot-scope="scope">
                        <img :src="scope.row.activity_info.cover_img" alt="" style="width: 100px;">
                    </template>
                </el-table-column>
                <el-table-column prop="money" label="报名费">
                </el-table-column>
                <el-table-column prop="points" label="赠送积分"></el-table-column>
                <el-table-column prop="order_sn" label="订单号" min-width="180"></el-table-column>
                <el-table-column prop="pay_time" label="支付时间" min-width="120">
                    <template slot-scope="scope">
                        {{formatDate(scope.row.pay_time)}}
                    </template>
                </el-table-column>
                <el-table-column prop="status" label="报名状态"></el-table-column>
                <el-table-column prop="create_time" label="报名时间" min-width="120">
                    <template slot-scope="scope">
                        {{formatDate(scope.row.create_time)}}
                    </template>
                </el-table-column>

            </el-table>
            <el-pagination background layout="total,prev, pager, next" :total="totalNum" :page-size="10"
                           :current-page.sync="currentPage" @current-change="getData"></el-pagination>
        </el-tab-pane>
    </el-tabs>
</div>
</body>
<script>
    var app = new Vue({
        el: '#app',
        data: function () {
            return {
                tableData: [],
                companyData: [],
                form: {
                    name: '',
                },
                totalNum: 0,
                currentPage: 1,
                dialogLoading: false,
                onDataLoading: false,
                durationOptions: {
                    shortcuts: [{
                        text: '一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            end.setTime(end.getTime() + 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            end.setTime(end.getTime() + 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            end.setTime(end.getTime() + 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                dialogVisible: false,
                headers: {'X-Requested-With': 'XMLHttpRequest'},
            }
        },
        created() {
            this.getCompanyData();
            this.getData()
        },
        methods: {
            clearForm() {
                this.form = {
                    name: '',
                }
            },
            getData(page = 1) {
                let _this = this;
                let params = {page: page};
                this.onDataLoading = true;
                if (this.form.duration !== '') {
                    params.duration = this.form.duration;
                }
                axios.get("{:url('admin/activity/sign_list')}", {
                    headers: {
                        'X-Requested-With': 'XMLHttpRequest',
                    },
                    params: params
                }).then(function (response) {
                    console.log(response.data.data);
                    _this.onDataLoading = false;
                    if (response.data.code === 1) {
                        _this.tableData = response.data.data.data;
                        _this.totalNum = response.data.data.total;
                        console.log(_this.totalNum)
                    } else {
                        _this.$message({
                            message: response.data.msg,
                            type: 'warning'
                        });
                    }
                }).catch(function (error) {
                    _this.onDataLoading = false;
                    _this.$message.error(error.toString())
                })
            },
            getCompanyData() {
                let _this = this;
                axios.get("{:url('admin/company/get_company_list')}", {
                    headers: {
                        'X-Requested-With': 'XMLHttpRequest',
                    },
                }).then(function (response) {
                    _this.onDataLoading = false;
                    if (response.data.code === 1) {
                        _this.companyData = response.data.data;
                    } else {
                        _this.$message({
                            message: response.data.msg,
                            type: 'warning'
                        });
                    }
                }).catch(function (error) {
                    _this.onDataLoading = false;
                    _this.$message.error(error.toString())
                })
            },
            formatDate(timestamp) {
                if (timestamp) {
                    let date = new Date(timestamp * 1000);
                    return date.getFullYear() + '-' + this.prefix(date.getMonth() + 1) + '-' + this.prefix(date.getDate()) + ' ' + this.prefix(date.getHours()) + ':' + this.prefix(date.getMinutes()) + ':' + this.prefix(date.getSeconds());
                } else {
                    return '';
                }
            },
            prefix(num) {
                if (num < 10) {
                    return '0' + num;
                }
                return num;
            }
        }
    });
</script>
